---
title: "replication file 2 13 25"
output: html_document
date: "2025-02-13"
---

```{r Load packages and files}

## Loading all necessary packages

library(readxl)
library(foreign)
library(lfe)
library(fixest)
library(nnet)
library(stargazer)
library(xtable)
library(car)
library(broom)
library(estimatr)
library(plotrix)
library(tidyverse)
library(Hmisc)
library(sf)
library(tmap)
library(haven)
source("replication_data/m_n_functions.R")

## Importing difftest function

# https://kzee.github.io/CoeffDiff_Demo.html
difftest_lm <- function(x1, x2, model){
  diffest <- summary(model)$coef[x1,"Estimate"]-summary(model)$coef[x2,"Estimate"]
  vardiff <- (summary(model)$coef[x1,"Std. Error"]^2 + 
                summary(model)$coef[x2,"Std. Error"]^2) - (2*(vcov(model)[x1, x2])) 
  # variance of x1 + variance of x2 - 2*covariance of x1 and x2
  diffse <- sqrt(vardiff)
  tdiff <- (diffest)/(diffse)
  ptdiff <- 2*(1-pt(abs(tdiff), model$df, lower.tail=T))
  upr <- diffest + qt(.975, df = model$df)*diffse # will usually be very close to 1.96
  lwr <- diffest + qt(.025, df = model$df)*diffse
  df <- model$df
  return(list(est=round(diffest, digits =2), 
              t=round(tdiff, digits = 2), 
              p=round(ptdiff, digits = 4), 
              lwr=round(lwr, digits = 2), 
              upr=round(upr, digits = 2),
              df = df))
}

```

# Part I: Qualitative Case Studies

### Table 1. Case Study Characteristics

```{r Table 1}

## Function to import table

import_socexp <- function(x) {
  read_csv(x) %>%
    dplyr::select(fips_place = Geo_FIPS, place_name_acs = Geo_NAME, tot_housing_units = SE_A10001_001,
                  occupied_housing = SE_A10060_001, owner_occupied = SE_A10060_002,
                  renter_occupied = SE_A10060_003, 
                tot_pop = SE_A00001_001,  density = SE_A00002_002, 
                pop_65 = SE_A01001B_010, 
         white_non_hisp = SE_A04001_003, black_non_hisp  = SE_A04001_004, asian_non_hisp = SE_A04001_006,
         white_hisp = SE_A04001_011, black_hisp = SE_A04001_012, asian_hisp = SE_A04001_014, hispanic  = SE_A04001_010,  
          ba_or_more = SE_A12001_005,
          ba_pct = PCT_SE_A12001_005,
         # inflation adjusted to 2021
         med_inc = SE_A14006_001,
         # how many people live in a house (of all occupied housing units)
         house_sz_one = PCT_SE_A10024_002, house_sz_two = PCT_SE_A10024_003,
         house_sz_three= PCT_SE_A10024_004, house_sz_four = PCT_SE_A10024_005,
         house_sz_five = PCT_SE_A10024_006, house_sz_six = PCT_SE_A10024_007,
         house_sz_seven = PCT_SE_A10024_008, 
         # % of housing units that are single-family detached
         sf_detached_pct = PCT_SE_A10032_003,  units3_4_pct = PCT_SE_A10032_006,
         units5_9_pct = PCT_SE_A10032_007, units10_19_pct = PCT_SE_A10032_008, 
         units20_49_pct = PCT_SE_A10032_009, units50_pct = PCT_SE_A10032_010,
         # how many units are in a building (of all occupied housing units)
         building_size_detached = PCT_SE_A10053_002, building_size_attached = PCT_SE_A10053_003,
         building_size_two = PCT_SE_A10053_004, building_size_3_4 = PCT_SE_A10053_005,
         building_size_5_9 = PCT_SE_A10053_006, building_size_10_19 = PCT_SE_A10053_007,
         building_size_20_49 = PCT_SE_A10053_008, building_size_over50 = PCT_SE_A10053_009,
         mobile_home = PCT_SE_A10053_010, rv_van = PCT_SE_A10053_011,
         # year housing units built (of all occupied housing units)
         built_after_2005 = PCT_SE_A10055_002,
         # occupants per room (out of total renter occupied units)
         room_occ1_15 = PCT_SE_A10046B_004, room_occ15_2 = PCT_SE_A10046B_005, room_occ2plus = PCT_SE_A10046B_006,
         med_yr_built = SE_A10057_001,
         # house value for owner-occup housing
         med_home_val = SE_A10036_001,
         # rent as percent of household income over last 12 months, more than
         gross_rent_over10 = PCT_SE_A18011_002, gross_rent_over20 = PCT_SE_A18011_003, 
         gross_rent_over30 = PCT_SE_A18011_004, gross_rent_over40 = PCT_SE_A18011_005, 
         med_gross_rent = SE_A18009_001, med_rent_incprop = SE_A18003_001,
         med_mortgage_incprop = SE_A10037_001,
         avg_work_commute = SE_A09003_001) %>%
    mutate(black_pct = ((black_hisp + black_non_hisp)/tot_pop)*100,
           asian_pct = ((asian_hisp + asian_non_hisp)/tot_pop)*100,
           white_all_pct = ((white_non_hisp + white_hisp)/tot_pop)*100,
           # % of occupied housing units that are owner-occupied (not % of ppl who are owners)
           owner_occ_pct = ifelse(occupied_housing > 0, (owner_occupied/occupied_housing)*100, NA),
                  renter_occ_pct = ifelse(occupied_housing > 0, (renter_occupied/occupied_housing)*100, NA),
           pop_65_pct = (pop_65/tot_pop)*100,
           white_pct = (white_non_hisp/tot_pop)*100,
           hispanic_pct = (hispanic/tot_pop)*100,
           fips_place = as.numeric(fips_place),
           units_over4_pct = units5_9_pct + units10_19_pct + units20_49_pct + units50_pct,
           file = x)
}

## Loading field site data

field_sites <- import_socexp("replication_data/field_site_data2022.csv") %>%
  separate(place_name_acs, c("place_name", "other"), ", California")%>%
  separate(place_name, c("place_name", "other"), -5) %>%
  mutate_each(funs(tolower), place_name) %>%
  filter(place_name %in% c("belmont", "menlo park", "yorba linda"))  %>%
  dplyr::select(place_name, tot_pop,  asian_pct, hispanic_pct, black_pct, white_pct,
                med_inc, ba_pct, owner_occ_pct, med_home_val)

## Loading CA voting data

ca_vote <- read_csv("replication_data/state_g20_sov_data_by_g20_srprec.csv") %>%
  dplyr::select(fips = FIPS, srprec = SRPREC, TOTVOTE, PRSDEM01)

## Loading CA registration data

ca_precinct_reg_nov2020 <- read_csv("replication_data/state_g20_registration_by_g20_srprec.csv") %>%
  dplyr::select(FIPS, SRPREC_KEY, TOTREG_R, DEM) %>%
  rename(dem_count = DEM, registered = TOTREG_R, fips = FIPS) %>%
  mutate(srprec = str_sub(SRPREC_KEY, 6))

## Merging CA city data together

field_sites_pid <- read_csv("replication_data/state_g20_to_city_by_g20_srprec.csv") %>% 
  rename(fips = FIPS, srprec = SRPREC) %>%
  left_join(ca_precinct_reg_nov2020, by = c("fips", "SRPREC_KEY", "srprec")) %>%
  left_join(ca_vote, by = c("fips", "srprec")) %>%
  group_by(fips, CITY) %>%
  dplyr::summarize(dem = sum(dem_count, na.rm = TRUE),
            registered = sum(registered, na.rm = TRUE),
            dem_vote = sum(PRSDEM01, na.rm = TRUE),
            tot_vote = sum(TOTVOTE, na.rm = TRUE)) %>%
  mutate(dem_pct = (dem/registered)*100,
         dem_pct_vote = (dem_vote/tot_vote)*100) %>%
  filter(fips %in% c("06059", "06081"),
         CITY %in% c("YORBA LINDA", "MENLO PARK", "BELMONT")) %>%
  mutate(place_name = ifelse(CITY == "YORBA LINDA", "yorba linda",
                             ifelse(CITY == "MENLO PARK", "menlo park", "belmont")))

## Loading ACS Place data

all_places_data <- read_csv("replication_data/acs_places_2022.csv") %>%
    dplyr::select(fips_pla = Geo_FIPS, name = Geo_QName, tot_housing_units = SE_A10032_001,
                  occupied_housing = SE_A10060_001, owner_occupied = SE_A10060_002,
                  renter_occupied = SE_A10060_003, 
                tot_pop = SE_A00001_001,  density = SE_A00002_002, 
         white_non_hisp = SE_A04001_003, black_non_hisp  = SE_A04001_004, asian_non_hisp = SE_A04001_006,
         white_hisp = SE_A04001_011, black_hisp = SE_A04001_012, asian_hisp = SE_A04001_014, hispanic  = SE_A04001_010,  
          ba_or_more = SE_A12001_005,
          ba_pct = PCT_SE_A12001_005,
         # household, inflation adjusted to 2022
         med_inc = SE_A14006_001,
         med_home_val = SE_A10036_001,
         # % of housing units that are single-family detached
         sf_detached_pct = PCT_SE_A10032_003,  units3_4_pct = PCT_SE_A10032_006,
         units5_9_pct = PCT_SE_A10032_007, units10_19_pct = PCT_SE_A10032_008, 
         units20_49_pct = PCT_SE_A10032_009, units50_pct = PCT_SE_A10032_010) %>%
    mutate(black_pct = ((black_hisp + black_non_hisp)/tot_pop)*100,
           asian_pct = ((asian_hisp + asian_non_hisp)/tot_pop)*100,
           white_all_pct = ((white_non_hisp + white_hisp)/tot_pop)*100,
           # % of occupied housing units that are owner-occupied (not % of ppl who are owners)
           owner_occ_pct = ifelse(occupied_housing > 0, (owner_occupied/occupied_housing)*100, NA),
                  renter_occ_pct = ifelse(occupied_housing > 0, (renter_occupied/occupied_housing)*100, NA),
           white_pct = (white_non_hisp/tot_pop)*100,
           hispanic_pct = (hispanic/tot_pop)*100,
           black_non_hisp_pct = (black_non_hisp/tot_pop)*100,
           asian_non_hisp_pct = (asian_non_hisp/tot_pop)*100,
           other_pct =((tot_pop-asian_non_hisp-black_non_hisp-white_non_hisp-hispanic)/tot_pop)*100,
           units_over4_pct = units5_9_pct + units10_19_pct + units20_49_pct + units50_pct) %>%
  filter(grepl("California", name)) %>%
  dplyr::select(fips_pla, tot_pop,  asian_pct, hispanic_pct, black_pct, white_pct,
                med_inc, ba_pct, owner_occ_pct, med_home_val) %>%
  summarise(tot_pop = quantile(tot_pop, .75, na.rm = TRUE),
            asian_pct = quantile(asian_pct, .75, na.rm = TRUE),
            hispanic_pct = quantile(hispanic_pct, .75, na.rm = TRUE),
            black_pct = quantile(black_pct, .75, na.rm = TRUE),
            white_pct = quantile(white_pct, .75, na.rm = TRUE),
            med_inc = quantile(med_inc, .75, na.rm = TRUE),
            ba_pct = quantile(ba_pct, .75, na.rm = TRUE),
            owner_occ_pct = quantile(owner_occ_pct, .75, na.rm = TRUE),
            med_home_val = quantile(med_home_val, .75, na.rm = TRUE)) %>%
  mutate(place_name = "All CA Places")

field_sites.x <- left_join(field_sites, field_sites_pid, by = "place_name")  %>%
  bind_rows(all_places_data)

print(xtable(t(mapply("format", field_sites.x, digits=3))))

```

### Figure 1. measure v results by precinct

```{r Figure 1}

## Loading Election Results data

measure_v <- read_csv("replication_data/sm_election_2022.csv") %>%
  filter(grepl("Measure V", Contest_title)) %>%
  dplyr::select(Precinct_name, Split_name, candidate_name, total_votes) %>%
  spread(candidate_name, total_votes) %>%
  mutate(tot_votes = NO + YES,
         no_pct = ifelse(tot_votes>0, NO/tot_votes, NA),
         yes_pct = ifelse(tot_votes>0, YES/tot_votes, NA),
         SRPREC = as.character(Precinct_name))

## Loading precinct shapefiles

sm_precincts <- st_read("replication_data/srprec_081_g22_v01_shp/srprec_081_g22_v01.shp") %>%
  left_join(measure_v, by = "SRPREC") %>%
  filter(!is.na(NO))

sm_centroids <- st_centroid(sm_precincts) %>%
  mutate(n = row_number())

# lat/long of flood school site at 321 sheridan dr: 37.477602, -122.170883
flood.sfg <- st_point(c( -122.170883, 37.477602), dim = "XY")
flood.sfc <- st_sfc(flood.sfg, crs = "NAD83")

dist <- data.frame(c(st_distance(sm_centroids$geom[], flood.sfc)/1000))  %>%
  mutate(n = row_number())

## Create Figure 1

fig1 <- tm_shape(sm_precincts) + 
  tm_fill("no_pct", 
          title = "No %", 
          palette = "Blues",
          ### changed to NA from NULL
            colorNA = "white", 
          textNA = ""
          ) +
  tm_borders(alpha = .1) + 
  ### moving to center of left, not bottom
  tm_layout(legend.position = c("left", "center"),
            frame = FALSE) +
tm_shape(flood.sfc) +
tm_dots(fill = "red", size = 1)

tmap_save(fig1, filename = "figs/fig1.pdf", width = 11.7, height = 5.8,
    dpi = 800)

```

### Tables 2-4 (in-text): Case Study Logic; Sample Demographic Characteristics; Local Info Sources

# Part II: Generalizability

### Figure 2. Ballot Measure Arguments

```{r Figure 2}

## Load ballot data

ballot_args <- read_excel("replication_data/ballot_args 10 29 24.xlsx") 

## Create Figure 2

fig2 <-
ballot_args %>%
  filter(data_available == "both_found") %>%
  mutate(distributional_argument = as.numeric(distributional_argument),
         residents_support = as.numeric(residents_support),
         property_rights = as.numeric(property_rights)) %>%
  replace_na(list(distributional_argument = 0 , environmental_argument = 0, 
                  property_rights = 0, residents_support = 0, us_vs_them = 0)) %>%
  mutate(total = n(),
         ideological_argument = ifelse(distributional_argument == 1 | environmental_argument == 1 |
                                         property_rights == 1, 1, 0),
         norms_argument = ifelse(residents_support == 1 | us_vs_them == 1, 1, 0),
         both = ifelse(ideological_argument == 1 & norms_argument == 1, 1, 0),
         either = ifelse(ideological_argument == 1 | norms_argument == 1, 1, 0),
         neither = ifelse(ideological_argument == 1, 0,
                          ifelse(norms_argument == 1, 0, 1))) %>%
  dplyr::select(argument_type, place_name, year, month, meas_letter, total, ideological_argument:neither) %>%
  gather( "arg_type", "value", -argument_type, -place_name, -year, -month, -meas_letter, -total) %>%
  mutate(value = as.numeric(value),
         arg_type = as.factor(ifelse(arg_type == "ideological_argument", "Ideological Argument",
                           ifelse(arg_type == "norms_argument", "Community-Group Cue",
                                  ifelse(arg_type == "both", "Both", 
                                  ifelse(arg_type == "either", "Either", "Neither"))))),
         arg_type = fct_relevel(arg_type, c("Ideological Argument", "Community-Group Cue", "Both", "Either", "Neither"))) %>%
  replace_na(list(value = 0 )) %>%
  group_by(arg_type) %>%
  mutate(type_count = sum(value),
         pct = (type_count/total)*100)  %>%
  distinct(arg_type, pct) %>%
  rename("Argument Type" = arg_type) %>%
  ggplot(aes(`Argument Type`, pct)) +
  geom_bar(stat = "identity") +
  theme_bw() +
  ylim(0, 75) +
  labs(y = "Percent of Ballot Arguments Making Claim", y = "Type of Claim") +
  theme(axis.text.x = element_text(angle = 45, vjust = 0.5))

 ggsave("figs/fig2.pdf")

```

### Figure 3. Effects on MFH Support 

```{r Figure 3 Data Cleaning}

## Cleaning Data

zip_dense <- read_csv("replication_data/acs_zip_dense.csv") %>%
  dplyr::select(ZIP = Geo_ZCTA5, zip_dens = SE_A00002_002)

load("replication_data/zip_apsa_imputed22.Rdata") 
zip <- zip %>%
  dplyr::select(ZIP = zipnew, pctr082)

data_c2 <- read_csv("replication_data/data_cr 11 25 24.csv") %>% 
  dplyr::select(ip_address = 4, country = 24, 
                ZIP, state,
                city1, duration, housing = 25,
                age = 31, gender = 32,
                race = 33, latino = 34,
                education = 35,
                income = 36,
         party_id = 26,
         party_id2 = 27,
         party_id3 = 28,
         party_id4 = 29, 
         ideology = 30,
         attn_check = 40,
         local_ctrl = 41,
         tod = 42,
         duplex_devel = 43,
         pub_schools = 44,
         g_and_t = 45,
         parent_input = 46,
         # post-treatment
         strong_support = 47,
         weak_support = 48,
         distributive = 49,
         control = 50,
         town_approval = 51,
         supp_selfish = 52,
         supp_comm = 53,
         supp_good = 54,
         supp_lib = 55,
         supp_conserv = 56,
         opp_selfish = 57,
         opp_comm = 58,
         opp_good = 59,
         opp_lib = 60,
         opp_conserv = 61, incorrect_city) %>%
  mutate(gender = ifelse(gender == "Male", 1, 0),
         age = as.numeric(age),
         latino = ifelse(latino == "Hispanic or Latino", 1, 0),
         white = ifelse(race == "White", 1, 0),
         black = ifelse(race == "Black or African American", 1, 0),
         asian = ifelse(race %in% c("Asian", "Native Hawaiian or Pacific Islander"), 1, 0),
         other = ifelse(race %in% c("Some other race", "American Indian or Alaska Native"), 1, 0),
         ba_or_more = ifelse(education %in% c("College degree", "Some graduate school", "Graduate school"), 1, 0),
         income = ifelse(income == "Less than $15,000", 1, 
                         ifelse(income == "$15,000-24,999", 2,
                         ifelse(income == "$25,000-34,999", 3,
                         ifelse(income == "$35,000-49,999", 4,
                         ifelse(income == "$50,000-74,999", 5,
                         ifelse(income == "$100,000-119,999", 6,
                         ifelse(income == "$120,000-149,999", 7, 8))))))),
         over_100k = ifelse(income >= 6, 1, 0),
         party_id_scale = ifelse(party_id == "Democrat" & party_id2 == "Strong", 0,
                                     ifelse(party_id == "Democrat" & party_id2 == "Not very strong", 1,
                                            ifelse(party_id == "Independent" & party_id4 == "Closer to the Democratic Party", 2,
                                            ifelse(party_id == "Independent" & party_id4 == "Neither", 3,
                               ifelse(party_id == "Independent" & party_id4 == "Closer to the Republican Party", 4,
                                      ifelse(party_id == "Republican" & party_id3 == "Not very strong", 5, 
                                      ifelse(party_id == "Republican" & party_id3 == "Strong", 6, NA))))))),
         local_ctrl = ifelse(local_ctrl == "Strongly support", 5, 
                                ifelse(local_ctrl == "Somewhat support",4, 
                                ifelse(local_ctrl == "Neither support or oppose",3, 
                                ifelse(local_ctrl == "Somewhat oppose",2,1)))),
         duplex_devel = ifelse(duplex_devel == "Strongly support", 5, 
                                ifelse(duplex_devel == "Somewhat support",4, 
                                ifelse(duplex_devel == "Neither support or oppose",3, 
                                ifelse(duplex_devel == "Somewhat oppose",2,1)))),
         tod = ifelse(tod == "Strongly support", 5, 
                                ifelse(tod == "Somewhat support",4, 
                                ifelse(tod == "Neither support or oppose",3, 
                                ifelse(tod == "Somewhat oppose",2,1)))),
         g_and_t = ifelse(g_and_t == "Strongly support", 5, 
                                ifelse(g_and_t == "Somewhat support",4, 
                                ifelse(g_and_t == "Neither support or oppose",3, 
                                ifelse(g_and_t == "Somewhat oppose",2,1)))),
         pub_schools = ifelse(pub_schools == "Strongly support", 5, 
                                ifelse(pub_schools == "Somewhat support",4, 
                                ifelse(pub_schools == "Neither support or oppose",3, 
                                ifelse(pub_schools == "Somewhat oppose",2,1)))),
         parent_input = ifelse(parent_input == "Strongly support", 5, 
                                ifelse(parent_input == "Somewhat support",4, 
                                ifelse(parent_input == "Neither support or oppose",3, 
                                ifelse(parent_input == "Somewhat oppose",2,1)))),
        # party_id_scale = (party_id_scale-1)/3,
         condition = as.factor(ifelse(!is.na(strong_support), "strong_support",
                            ifelse(!is.na(weak_support), "weak_support", 
                            ifelse(!is.na(distributive), "distributive",
                            ifelse(!is.na(control), "control","other"))))),
         mfh_devel_dv = ifelse(condition == "strong_support", strong_support,
                               ifelse(condition == "weak_support", weak_support, 
                               ifelse(condition == "distributive", distributive, 
                               ifelse(condition == "control", control,NA)))),
         mfh_devel_post = ifelse(mfh_devel_dv == "Strongly support", 5, 
                                ifelse(mfh_devel_dv == "Somewhat support",4, 
                                ifelse(mfh_devel_dv == "Neither support or oppose",3, 
                                ifelse(mfh_devel_dv == "Somewhat oppose",2,1)))),
         mfh_devel_post_binary = ifelse(mfh_devel_dv %in% c("Strongly support",  "Somewhat support"),1, 0),
         opp_selfish = ifelse(opp_selfish == "Extremely well",  5, 
                                     ifelse(opp_selfish == "Very well" , 4, 
                              ifelse(opp_selfish == "Somewhat well", 3, 
                              ifelse(opp_selfish == "Not too well",  2,  1)))),
         opp_comm = ifelse(opp_comm == "Extremely well",  5, 
                                     ifelse(opp_comm == "Very well" , 4, 
                              ifelse(opp_comm == "Somewhat well", 3, 
                              ifelse(opp_comm == "Not too well",  2,  1)))),
         opp_good = ifelse(opp_good == "Extremely well",  5, 
                                     ifelse(opp_comm == "Very well" , 4, 
                              ifelse(opp_good == "Somewhat well", 3, 
                              ifelse(opp_good == "Not too well",  2,  1)))),
         opp_lib = ifelse(opp_lib == "Extremely well",  5, 
                                     ifelse(opp_lib == "Very well" , 4, 
                              ifelse(opp_lib == "Somewhat well", 3, 
                              ifelse(opp_lib == "Not too well",  2,  1)))),
         opp_conserv = ifelse(opp_conserv == "Extremely well",  5, 
                                     ifelse(opp_conserv == "Very well" , 4, 
                              ifelse(opp_conserv == "Somewhat well", 3, 
                              ifelse(opp_conserv == "Not too well",  2,  1)))),
         
         supp_selfish = ifelse(supp_selfish == "Extremely well",  5, 
                                     ifelse(supp_selfish == "Very well" , 4, 
                              ifelse(supp_selfish == "Somewhat well", 3, 
                              ifelse(supp_selfish == "Not too well",  2,  1)))),
         supp_comm = ifelse(supp_comm == "Extremely well",  5, 
                                     ifelse(supp_comm == "Very well" , 4, 
                              ifelse(supp_comm == "Somewhat well", 3, 
                              ifelse(supp_comm == "Not too well",  2,  1)))),
         supp_good = ifelse(supp_good == "Extremely well",  5, 
                                     ifelse(supp_good == "Very well" , 4, 
                              ifelse(supp_good == "Somewhat well", 3, 
                              ifelse(supp_good == "Not too well",  2,  1)))),
         supp_lib = ifelse(supp_lib == "Extremely well",  5, 
                                     ifelse(supp_lib == "Very well" , 4, 
                              ifelse(supp_lib == "Somewhat well", 3, 
                              ifelse(supp_lib == "Not too well",  2,  1)))),
         supp_conserv = ifelse(supp_conserv == "Extremely well",  5, 
                                     ifelse(supp_conserv == "Very well" , 4, 
                              ifelse(supp_conserv == "Somewhat well", 3, 
                              ifelse(supp_conserv == "Not too well",  2,  1)))),
        supp_opp_self = supp_selfish-opp_selfish,
        supp_opp_comm = supp_comm-opp_comm,
        supp_opp_good = supp_good-opp_good,
        supp_opp_libl = supp_lib -opp_lib,
        supp_opp_cons = supp_conserv - opp_conserv,
        town_approval = as.numeric(town_approval),
        dem_scale = ifelse(party_id == "Democrat" & party_id2 == "Strong", 1,
                           ifelse(party_id == "Democrat" & party_id2 == "Not very strong", .5,
                           ifelse(party_id == "Independent" & party_id4 == "Closer to the Democratic Party", 0, NA))),
        p_id_scale = ifelse(party_id == "Democrat" & party_id2 == "Strong", 1,
                           ifelse(party_id == "Democrat" & party_id2 == "Not very strong", (1/6)*5,
                           ifelse(party_id == "Independent" & party_id4 == "Closer to the Democratic Party", (1/6)*4, 
                           ifelse(party_id == "Independent" & party_id4 == "No, neither", (1/6)*3, 
                           ifelse(party_id == "Independent" & party_id4 == "Closer to the Republican Party", (1/6)*2, 
                           ifelse(party_id == "Republican" & party_id3 == "Not very strong", (1/6), 
                           ifelse(party_id == "Republican" & party_id3 == "Strong", 0, NA))))))),
        homeowner = ifelse(housing == "I own it", 1,0)) %>%
  left_join(zip, by = "ZIP") %>%
  left_join(zip_dense, by = "ZIP") %>%
  mutate(zip_density_terc = tercileAssign(zip_dens),
         high_dens_zip = ifelse(zip_density_terc == 3, 1, 0),
         low_dens_zip = ifelse(zip_density_terc == 1, 1, 0),
         dem_zip = ifelse(pctr082 <= quantile(pctr082, .5, na.rm = TRUE), 1, 0),
         duplicate = ifelse(ZIP == "30002" & city1 == "avondale estates" &
                            age == 24 & gender == 1 & race == "White" & education == "Graduate school" &
                            income == 7 & party_id == "Democrat", 1,
                      ifelse(ZIP == "14210" & city1 == "buffalo" &
                            age == 24 & gender == 1 & race == "White" & education == "College degree" &
                            income == 6 & party_id == "Republican", 1,0))) %>%
  filter(incorrect_city == 0,
         attn_check == "Red,Green",
         duplicate != 1) 




```

```{r Figure 3}

## Generate Figure

data_c2$condition <- factor(data_c2$condition, levels = c("control", "distributive", 
                                                          "strong_support", 
                                                          "weak_support"), 
                       labels = c("Control", "Distributive", 
                                  "Strong Support", "Weak Support" ))


m1 <- lm_robust(mfh_devel_post ~ condition, data = data_c2)
m2 <- lm_robust(mfh_devel_post ~ condition + p_id_scale + homeowner + latino + 
                  asian + black + white + age + income + ba_or_more + gender  +
                  local_ctrl + tod + duplex_devel + parent_input + g_and_t +
                  pub_schools + zip_dens, data = data_c2)
difftest_lm("conditionWeak Support", "conditionStrong Support", m1)

fig3 <-
tidy(m1)  %>%
  filter(grepl("condition", term)) %>%
  mutate(Condition = ifelse(grepl("Distributive", term), "Distributive",
                            ifelse(grepl("Strong", term), "Strong Support", "Weak Support")),
         Condition = fct_relevel(Condition, c("Weak Support", "Strong Support",  "Distributive"))) %>%
  ggplot() + 
  aes(x = Condition, y = estimate) + 
  geom_hline(yintercept = 0, lty = 3) + 
  geom_point() + 
  geom_linerange(aes(ymin = estimate - 1.645 * std.error, ymax = estimate + 1.645 * std.error), position = position_dodge(width = .35), lwd=1.5)+
  geom_linerange(aes(ymin = estimate - 1.96 * std.error, ymax = estimate + 1.96 * std.error), position = position_dodge(width = .35), lwd=.5)+
  labs(y = "", x = "") +
  theme_bw() +
  theme(text=element_text(size=12,  family="Times")) + 
  coord_flip()
ggsave("figs/fig3.pdf")



```

### Figure 4.Effects on Town Approval

```{r Figure 4}

## Linear modeling

t1 <- lm_robust(town_approval ~ condition, data = data_c2)
t2 <- lm_robust(town_approval ~ condition + p_id_scale + homeowner + latino + asian +
                  black + white + age + income + ba_or_more + gender  + local_ctrl +
                  tod + duplex_devel + parent_input + g_and_t + pub_schools +
                  zip_dens, data = data_c2)
difftest_lm("conditionWeak Support", "conditionStrong Support", t1)

## Create Figure 4

fig4 <-
  tidy(t1)  %>%
  filter(grepl("condition", term)) %>%
  mutate(Condition = ifelse(grepl("Distributive", term), "Distributive",
                            ifelse(grepl("Strong", term), "Strong Support", "Weak Support")),
         Condition = fct_relevel(Condition, c("Weak Support", "Strong Support",  "Distributive"))) %>%
  ggplot() + 
  aes(x = Condition, y = estimate) + 
  geom_hline(yintercept = 0, lty = 3) + 
  geom_point() + 
  geom_linerange(aes(ymin = estimate - 1.645 * std.error, ymax = estimate + 1.645 * std.error), position = position_dodge(width = .35), lwd=1.5)+
  geom_linerange(aes(ymin = estimate - 1.96 * std.error, ymax = estimate + 1.96 * std.error), position = position_dodge(width = .35), lwd=.5)+
  labs(y = "", x = "") +
  theme_bw() +
  theme(text=element_text(size=12,  family="Times")) + 
  coord_flip()
ggsave("figs/fig4.pdf")

```

### Table 5. Effects on Characteristics

```{r Table 5}

## Linear modeling

m_s <- lm(supp_opp_self ~ condition + p_id_scale + homeowner +
                           latino + asian + black + white + age + 
                           income + ba_or_more + gender  + local_ctrl + 
                            tod + duplex_devel + parent_input + 
                           g_and_t + pub_schools + zip_dens, data = data_c2)

m_g <- lm(supp_opp_good ~ condition + p_id_scale + homeowner +
                           latino + asian + black + white + age + 
                           income + ba_or_more + gender  + local_ctrl + 
                            tod + duplex_devel + parent_input + 
                           g_and_t + pub_schools + zip_dens, data = data_c2)

m_cm <- lm(supp_opp_comm ~ condition + p_id_scale + homeowner +
                           latino + asian + black + white + age + 
                           income + ba_or_more + gender  + local_ctrl + 
                            tod + duplex_devel + parent_input + 
                           g_and_t + pub_schools + zip_dens, data = data_c2)

m_l <- lm(supp_opp_libl ~ condition + p_id_scale + homeowner +
                           latino + asian + black + white + age + 
                           income + ba_or_more + gender  + local_ctrl + 
                            tod + duplex_devel + parent_input + 
                           g_and_t + pub_schools + zip_dens, data = data_c2)


m_c <- lm(supp_opp_cons ~ condition + p_id_scale + homeowner +
                           latino + asian + black + white + age + 
                           income + ba_or_more + gender  + local_ctrl + 
                            tod + duplex_devel + parent_input + 
                           g_and_t + pub_schools + zip_dens, data = data_c2)

## Create Table 5

stargazer(m_s, m_g, m_cm, m_l, m_c, 
          # this passes the lm_robust default SEs to stargazer
          se = starprep(m_s, m_g, m_cm, m_l, m_c, se_type ="HC2"),
          star.cutoffs = c(0.05, 0.01, 0.001), omit.stat=c("LL","ser","f", "adj.rsq"), 
          ci=TRUE, ci.level=0.95, single.row=FALSE,
          covariate.labels = c("Distributive", "Strong Support", "Weak Support", 
                               "Party ID Scale", "Homeowner", 
                               "Latino", "Asian", "Black", "White",
                               "Age", "Income Scale", "College-Educated", "Gender",
                               "Neighborhood Voice",
                                "Transit-Oriented Development", 
                               "Duplexes in SFH Neighborhoods",  
                               "Parent Input in Curriculum",
                               "Getting Rid of Gifted & Talented", 
                               "Higher Taxes for Public Schools", 
                               "Zip Code Density"),
          omit = c("Constant"))

## Difference in Coefficients Tests

difftest_lm("conditionStrong Support", "conditionWeak Support", m_s)
difftest_lm("conditionStrong Support","conditionWeak Support",  m_g)
difftest_lm("conditionStrong Support","conditionWeak Support",  m_cm)
difftest_lm("conditionStrong Support", "conditionWeak Support", m_l)
difftest_lm( "conditionStrong Support","conditionWeak Support",m_c)

```

# APPENDIX

## Appendix A. Evidence that residential zoning is relatively non-partisan

### Figure A1. Relationship Between Local Partisan Composition & Housing vs. Environmental Voting

```{r Figure A1}

# data on precint-level votes
precinct_votes10_18 <- read_csv("replication_data/appendix/precinct_votes10_18 10 3 24.csv") %>%
  mutate(permiss_pct = 100-restrict_pct)

# see hazlett & midlenberger appendix for details on the vote

dem_reg_2010 <- read.dbf("replication_data/appendix/state_g10_registration_by_g10_srprec.dbf") %>%
  dplyr::select(FIPS, SRPREC_KEY, TOTREG_R, DEM)
ca_prop_23 <- read.dbf("replication_data/appendix/state_g10_sov_data_by_g10_srprec.dbf") %>%
  dplyr::select(COUNTY, SRPREC_KEY, PR_23_Y, PR_23_N) %>%
  left_join(dem_reg_2010, by = "SRPREC_KEY") %>%
  mutate(dem_pct = (DEM/TOTREG_R)*100,
         no_pct = PR_23_N/(PR_23_N+PR_23_Y)*100)

cor.test(ca_prop_23$dem_pct, ca_prop_23$no_pct)
cor.test(precinct_votes10_18$dem_pct, precinct_votes10_18$permiss_pct)

## Create Figure A1

figa1 <-
precinct_votes10_18 %>%
  mutate(vote = "(a) Residential Zoning, 2010-2018") %>%
  bind_rows(ca_prop_23) %>%
  mutate(vote = ifelse(is.na(vote), "(b) CA Environmental Measure, 2010", vote),
         leftist_pct = ifelse(vote == "(a) Residential Zoning, 2010-2018", permiss_pct,
                             ifelse(vote == "(b) CA Environmental Measure, 2010", no_pct, NA)),
         vote = fct_relevel(vote, c("(a) Residential Zoning, 2010-2018", 
                                                  "(b) CA Environmental Measure, 2010"))) %>%
  filter(leftist_pct>0, leftist_pct<100, dem_pct>0, dem_pct<100) %>%
  ggplot(aes(dem_pct, leftist_pct)) +
  geom_point() +
  geom_smooth() +
  theme_bw() +
  xlim(0, 100) +
  ylim(0,100) +
  coord_fixed() +
  facet_wrap(~vote) +
  labs(x = "% Registered as Democrat",
       y = "% Voting Permissively (a) or Pro-Environmentally (b)") 

ggsave("figs/figa1.pdf", width = 8, height = 4)

```

### Table A1. descriptives for dlabss

```{r Table A1}

## Load data from DLABSS

descripts_tab_dlabss <- read_csv("replication_data/appendix/dlabss_clean.csv")  %>%
  summarise("% Male"  = mean(gender, na.rm = TRUE),
            "% Homeowner" = mean(homeowner, na.rm = TRUE),
            "% Democrats" = mean(party_id_binary2, na.rm = TRUE),
            "% Black"  = mean(black, na.rm = TRUE),
            "% White"  = mean(white, na.rm = TRUE),
            "% Latinx"  = mean(latino, na.rm = TRUE),
            "% Income > 100k"  = mean(income_over100, na.rm = TRUE),
            "% College Educated"  = mean(ba_or_more, na.rm = TRUE),
            "Average Age"  = mean(age, na.rm = TRUE)) %>%
  mutate(across(2:9, round, 3)) %>%
  t()

## Create Table A1 

stargazer(descripts_tab_dlabss)

```

### Figure A2. Perceptions of Which Party Supports Different Zoning Policies

```{r Figure A2}

## Load data from DLABSS

dlabss_dat <-  read_csv("replication_data/appendix/dlabss_clean.csv") %>%
  dplyr::select(state_lib_zoning, relax_env_reg, expand_fed_funds, empower_local_ctrl) %>%
  gather("variable", "Response") %>%
  group_by(variable) %>%
  dplyr::mutate(count = n()) %>%
  ungroup() %>%
  group_by(variable, Response) %>%
  dplyr::summarise(n = n(),
         percentage = (n/count)*100) %>%
  filter(!is.na(Response)) %>%
  distinct(variable, Response, percentage) %>%
  mutate(variable = ifelse(variable == "state_lib_zoning", "Incent zoning liberalization",
                           ifelse(variable == "relax_env_reg", "Relax environ regs",
                           ifelse(variable == "expand_fed_funds", "Expand fed funding", "Empower local control"))),
         Response = as.factor(Response))

dlabss_dat$Response <- factor(dlabss_dat$Response, levels = c("Republican Party is more likely to support",
                                         "Democratic Party is more likely to support",
                                         "Both are equally likely to support", 
                                         "Neither is likely to support","Not Sure"), 
                       labels = c("Republican Party is more likely to support",
                                         "Democratic Party is more likely to support",
                                         "Both are equally likely to support", 
                                         "Neither is likely to support","Not Sure"))

dlabss_dat$variable <- factor(dlabss_dat$variable, 
                              levels = c("Expand fed funding", "Relax environ regs",
                                         "Incent zoning liberalization", 
                                         "Empower local control"), 
                       labels = c("Expand fed funding", "Relax environ regs", 
                                  "Incent zoning liberalization", 
                                  "Empower local control"))

## Create Figure A2

fig_a2 <-
  dlabss_dat %>% 
  ggplot(aes(x = variable, y = percentage, fill = Response)) +
  geom_bar(position="dodge", stat="identity") +
    scale_fill_manual(values= c("Red", "Blue", "Purple", "Green", "Orange")) +
  theme_bw() +
  theme(axis.text.x = element_text(angle = 45, vjust = 0.85, hjust=.75)) +
  labs(x = "",
       y = "% of Respondents per Category of Response")
ggsave("figs/fig_a2.pdf")

```

## Appendix B. Additional Information about Qualitative Cases

### Figure A3. top issues for yl and mp dems

```{r Figure A3}

## Create Figure A3

fig_a3 <-
  read_excel("replication_data/appendix/top_issues_mp_yl.xlsx") %>%
  mutate(percent = percent *100) %>% 
  mutate(issue = ifelse(issue == "demcoratic/institutional reforms", "democratic/institutional reforms", issue)) %>%
  filter(issue!="race") %>%
  mutate(issue=fct_relevel(issue,c("climate change/environment",
                                         "womens rights/roe vs wade",
                                         "redistribution or economic inequality", 
                                         "healthcare", "education",
                                   "democratic/institutional reforms", "guns", "immigration",
                                   "foreign policy/national security"))) %>%
  ggplot(aes(x = issue, y = percent, fill = city)) +
  geom_bar(position="dodge", stat="identity") +
  scale_fill_manual(values = c("blue1", "red1")) +
  theme_bw() +
  theme(axis.text.x = element_text(angle = 45, vjust = 0.8, hjust=.75)) +
  labs(x = "",
       y = "% of Respondents Listing Issue as Among Top National Concerns")

ggsave("figs/fig_a3.pdf")

```

## Appendix C. detailed results from experiment

### Table A2. Descriptive Stats 

```{r Table A2}

## Summarize data for means

descripts_data_c <- data_c2 %>%
  group_by(condition) %>% 
  summarise("% Male"  = mean(gender, na.rm = TRUE),
            "% Asian"  = mean(asian),
            "% Black"  = mean(black),
            "% Latinx"  = mean(latino),
            "% White"  = mean(white),
            "% Income > 100k"  = mean(over_100k),
            "% College Educated"  = mean(ba_or_more),
            "Average Age"  = mean(age)) %>%
  mutate(across(2:9, round, 2)) %>%
  t() 

## Create Table A2 means

stargazer(descripts_data_c)

## Summarize data for SEs
 
descripts_data_c2 <- data_c2 %>%
  dplyr::select(condition, gender, asian, black, latino, white,  over_100k ,  ba_or_more,  age) %>%
  group_by(condition) %>%
  summarise_each(funs(mean(., na.rm = TRUE),sd(., na.rm = TRUE),se=sd(., na.rm = TRUE)/sqrt(n())))  %>%
  dplyr::select(condition, contains("_se")) %>%
  mutate(across(2:9, round, 3)) %>%
  t()
 
## Create Table A2 SEs

stargazer(descripts_data_c2)
 
```

### Table A3. Detailed Regression Results for effects on MFH support 

```{r Table A3}

## Linear modeling

m_a1 <- lm(mfh_devel_post ~ condition, data = data_c2)
m_a2 <- lm(mfh_devel_post ~ condition + p_id_scale + homeowner + latino + asian +
             black +  white + age + income + ba_or_more + gender  + local_ctrl + 
             tod + duplex_devel + parent_input + g_and_t + pub_schools + 
             zip_dens, data = data_c2)

## Create Table A3

stargazer(m_a1, m_a2, 
          # this passes the lm_robust default SEs to stargazer
          se = starprep(m_a1, m_a2, se_type ="HC2"),
          star.cutoffs = c(0.05, 0.01, 0.001), omit.stat=c("LL","ser","f", "adj.rsq"), 
          ci=TRUE, ci.level=0.95, single.row=FALSE,
          covariate.labels = c("Distributive", "Strong Support", "Weak Support", 
                               "Party ID Scale", "Homeowner", 
                               "Latino", "Asian", "Black", "White",
                               "Age", "Income Scale", "College-Educated", "Gender",
                               "Neighborhood Voice",
                                "Transit-Oriented Development", 
                               "Duplexes in SFH Neighborhoods",  
                               "Parent Input in Curriculum",
                               "Getting Rid of Gifted & Talented", 
                               "Higher Taxes for Public Schools", 
                               "Zip Code Density"),
          omit = c("Constant"))

```

### Table A4.  Detailed Regression Results for Effects on Approval & Characteristics, No Controls

```{r Table A4}

## Linear modeling

m_t1 <- lm(town_approval ~ condition , data = data_c2)

m_s1 <- lm(supp_opp_self ~ condition , data = data_c2)


m_g1 <- lm(supp_opp_good ~ condition , data = data_c2)

m_cm1 <- lm(supp_opp_comm ~ condition , data = data_c2)

m_l1 <- lm(supp_opp_libl ~ condition , data = data_c2)

m_c1 <- lm(supp_opp_cons ~ condition , data = data_c2)

## Create Table A4

stargazer(m_t1, m_s1, m_g1, m_cm1, m_l1, m_c1, 
          # this passes the lm_robust default SEs to stargazer
          se = starprep(m_t1, m_s1, m_g1, m_cm1, m_l1, m_c1, se_type ="HC2"),
          star.cutoffs = c(0.05, 0.01, 0.001), omit.stat=c("LL","ser","f", "adj.rsq"), 
          ci=TRUE, ci.level=0.95, single.row=FALSE,
          covariate.labels = c("Distributive", "Strong Support", "Weak Support"),
          omit = c("Constant"))

```

### Table A5.  Detailed Regression Results for Effects on Approval & Characteristics, With Controls

```{r Table A5}

## Linear modeling

m_t <- lm(town_approval ~ condition + p_id_scale + homeowner +
                           latino + asian + black + white + age + 
                           income + ba_or_more + gender  + local_ctrl + 
                            tod + duplex_devel + parent_input + 
                           g_and_t + pub_schools + zip_dens, data = data_c2)

m_s <- lm(supp_opp_self ~ condition + p_id_scale + homeowner +
                           latino + asian + black + white + age + 
                           income + ba_or_more + gender  + local_ctrl + 
                            tod + duplex_devel + parent_input + 
                           g_and_t + pub_schools + zip_dens, data = data_c2)

m_g <- lm(supp_opp_good ~ condition + p_id_scale + homeowner +
                           latino + asian + black + white + age + 
                           income + ba_or_more + gender  + local_ctrl + 
                            tod + duplex_devel + parent_input + 
                           g_and_t + pub_schools + zip_dens, data = data_c2)

m_cm <- lm(supp_opp_comm ~ condition + p_id_scale + homeowner +
                           latino + asian + black + white + age + 
                           income + ba_or_more + gender  + local_ctrl + 
                            tod + duplex_devel + parent_input + 
                           g_and_t + pub_schools + zip_dens, data = data_c2)

m_l <- lm(supp_opp_libl ~ condition + p_id_scale + homeowner +
                           latino + asian + black + white + age + 
                           income + ba_or_more + gender  + local_ctrl + 
                            tod + duplex_devel + parent_input + 
                           g_and_t + pub_schools + zip_dens, data = data_c2)

m_c <- lm(supp_opp_cons ~ condition + p_id_scale + homeowner +
                           latino + asian + black + white + age + 
                           income + ba_or_more + gender  + local_ctrl + 
                            tod + duplex_devel + parent_input + 
                           g_and_t + pub_schools + zip_dens, data = data_c2)

## Create Table A5

stargazer(m_t, m_s, m_g, m_cm, m_l, m_c, 
          # this passes the lm_robust default SEs to stargazer
          se = starprep(m_t, m_s, m_g, m_cm, m_l, m_c, se_type ="HC2"),
          star.cutoffs = c(0.05, 0.01, 0.001), omit.stat=c("LL","ser","f", "adj.rsq"), 
          ci=TRUE, ci.level=0.95, single.row=FALSE,
           covariate.labels = c("Distributive", "Strong Support", "Weak Support", 
                               "Party ID Scale", "Homeowner", 
                               "Latino", "Asian", "Black", "White",
                               "Age", "Income Scale", "College-Educated", "Gender",
                               "Neighborhood Voice",
                                "Transit-Oriented Development", 
                               "Duplexes in SFH Neighborhoods",  
                               "Parent Input in Curriculum",
                               "Getting Rid of Gifted & Talented", 
                               "Higher Taxes for Public Schools", 
                               "Zip Code Density"),
          omit = c("Constant"))

```

### Table A6. Effects on Characteristics, by dem zip code

```{r Table A6}

## Linear Modeling

m_l2 <- lm(supp_opp_libl ~ condition*dem_zip + p_id_scale + homeowner +
                           latino + asian + black + white + age + 
                           income + ba_or_more + gender  + local_ctrl + 
                            tod + duplex_devel + parent_input + 
                           g_and_t + pub_schools + zip_dens, data = data_c2)

m_c2 <- lm(supp_opp_cons ~ condition*dem_zip + p_id_scale + homeowner +
                           latino + asian + black + white + age + 
                           income + ba_or_more + gender  + local_ctrl + 
                            tod + duplex_devel + parent_input + 
                           g_and_t + pub_schools + zip_dens, data = data_c2)

## Create Table A6

stargazer(m_l2, m_c2, 
          # this passes the lm_robust default SEs to stargazer
          se = starprep(m_l2, m_c2, se_type = "HC2"),
          star.cutoffs = c(0.05, 0.01, 0.001), omit.stat=c("LL","ser","f", "adj.rsq"), 
          ci=TRUE, ci.level=0.95, single.row=FALSE,
          covariate.labels = c("Distributive", "Strong Support", "Weak Support",
                               "Dem Zip Code",
                               "Party ID Scale", "Homeowner", 
                               "Latino", "Asian", "Black", "White",
                               "Age", "Income Scale", "College-Educated", "Gender",
                                "Transit-Oriented Development", "MGH in SFH Neighborhoods",  
                               "Neighborhood Voice","Getting Rid of Gifted & Talented", 
                               "Parent Input in Curriculum",
                               "Higher Taxes for Public Schools", 
                               "Zip Code Density", "Distributive:Dem Zip",
                               "Strong Support:Dem Zip", "Weak Support:Dem Zip"),
          omit = c("Constant"))

```

## Appendix D. Additional Survey and Experimental Evidence

### Table A7. cces desriptives

```{r Table A7}

## Load in CCES descriptives

cces <- read_sav("replication_data/appendix/CCES23_HU/CCES23_HU_refield_OUTPUT.sav") %>%
  mutate(supp_env_lax = ifelse(HU309_a_refield == 1, 1, 
                              ifelse(HU309_a_refield == 2, 0, NA)),
         supp_change_zoning = ifelse(HU309_b_refield == 1, 1, 
                              ifelse(HU309_b_refield == 2, 0, NA)),
         supp_adus = ifelse(HU309_c_refield == 1, 1, 
                              ifelse(HU309_c_refield == 2, 0, NA)),
         supp_override_zoning = ifelse(HU309_d_refield == 1, 1, 
                              ifelse(HU309_d_refield == 2, 0, NA)),
         mfh_devel_pre = ifelse(HU310a %in% c(1, 2), 1,
                               ifelse(HU310a %in% c(3, 4, 5), 0, NA)),
         mfh_devel_pre2 = ifelse(HU310a== 1, 5,
                                 ifelse(HU310a== 2, 4,
                                 ifelse(HU310a== 3, 3,
                                 ifelse(HU310a== 4, 2,
                                 ifelse(HU310a== 5, 1, NA))))),
         duplex_devel = ifelse(HU310a %in% c(1, 2), 1,
                               ifelse(HU310a %in% c(3, 4, 5), 0, NA)),
         strong_support = HU311_A,
         weak_support = HU311_B,
         strong_support_plus = HU311_C,
         condition = as.factor(ifelse(!is.na(HU311_A), "strong_support",
                            ifelse(!is.na(HU311_B), "weak_support", 
                            ifelse(!is.na(HU311_C), "strong_support_plus",NA)))),
         mfh_devel_post= ifelse(condition == "strong_support", strong_support,
                               ifelse(condition == "weak_support", weak_support, 
                               ifelse(condition == "strong_support_plus", strong_support_plus,NA))),
         mfh_devel_post = ifelse(mfh_devel_post== 1, 5,
                                 ifelse(mfh_devel_post== 2, 4,
                                 ifelse(mfh_devel_post== 3, 3,
                                 ifelse(mfh_devel_post== 4, 2,
                                 ifelse(mfh_devel_post== 5, 1, NA))))),
         mfh_change = mfh_devel_post-mfh_devel_pre2,
         city = ifelse(urbancity == 1, "city",
                       ifelse(urbancity == 2, "suburb",
                              ifelse(urbancity %in% c(3, 4, 5), "other", NA))),
         latino = ifelse(hispanic == 1, 1,
                         ifelse(hispanic == 2, 0, NA)),
         white = ifelse(race == 1, 1,
                         ifelse(race %in% c(2, 3, 4, 5, 6, 7, 8), 0, NA)),
         black = ifelse(race == 2, 1,
                         ifelse(race %in% c(1, 3, 4, 5, 6, 7, 8), 0, NA)),
         asian = ifelse(race == 4, 1,
                         ifelse(race %in% c(1, 2, 3, 5, 6, 7, 8), 0, NA)),
         p_id = ifelse(pid7 %in% c(1, 2, 3), "Democrat",
                       ifelse(pid7 %in% c(4), "Independent",
                              ifelse(pid7 %in% c(5, 6, 7), "Republican", "Other"))),
         p_id3 = ifelse(pid7 %in% c(1, 2, 3), 0,
                       ifelse(pid7 %in% c(4), .5,
                              ifelse(pid7 %in% c(5, 6, 7), 1, NA))),
         dem =  ifelse(pid7 %in% c(1, 2, 3), 1,
                              ifelse(pid7 %in% c(4, 5, 6, 7), 0, 0)),
         rep = ifelse(pid3 %in% c(5, 6, 7), 1,
                              ifelse(pid7 %in% c(1, 2, 3, 4), 0, 0)),
         age = 2023-birthyr,
         gender = ifelse(gender4 == 1, 1,
                       ifelse(gender4 %in% c(2, 3, 4), 0, NA)),
         ba_or_more = ifelse(educ %in% c(5,6), 1,
                       ifelse(educ %in% c(1, 2, 3, 4), 0, NA)),
         homeowner = ifelse(ownhome %in% c(1), 1,
                       ifelse(ownhome %in% c(2, 3), 0, NA)),
         income_over100k = ifelse(faminc_new >= 10 & faminc_new <= 16, 1,
                                  ifelse(faminc_new >= 1 & faminc_new < 10, 0, NA)),
         ZIP = lookupzip)  %>%
  left_join(zip_dense, by = "ZIP") %>%
  mutate(high_dens = ifelse(zip_dens > quantile(zip_dens, .5, na.rm = TRUE), 1, 0))

cces$condition <- factor(cces$condition, levels = c("weak_support","strong_support", "strong_support_plus"), 
                       labels = c("Weak Support","Strong Support", "Strong Support Plus Distributive"))

## Summarize means

descripts_tab_cces <- cces %>%
  filter(!is.na(condition)) %>%
  group_by(condition) %>% 
  summarise("% Homeowners"  = mean(homeowner, na.rm = TRUE),
            "% Democrats"  = mean(dem, na.rm = TRUE),
            "% Male"  = mean(gender, na.rm = TRUE),
            "% Asian"  = mean(asian, na.rm = TRUE),
            "% Black"  = mean(black, na.rm = TRUE),
            "% Hispanic/Latino"  = mean(latino, na.rm = TRUE),
            "% White"  = mean(white, na.rm = TRUE),
            "% Income > 100k"  = mean(income_over100k, na.rm = TRUE),
            "% College Educated"  = mean(ba_or_more, na.rm = TRUE),
            "Average Age"  = mean(age, na.rm = TRUE),
            "Avg Support for Multifamily Housing Development, Pre-Treatment"  = mean(mfh_devel_pre2, na.rm = TRUE)) %>%
  mutate(across(2:11, round, 3)) %>%
  t() 

## Create Table A7 means

stargazer(descripts_tab_cces)

## Summarize SEs

 descripts_tab_cces_se <- cces %>%
  filter(!is.na(condition)) %>%
  dplyr::select(condition, homeowner, dem, gender, asian, black, white, latino, 
                age,  income_over100k ,  ba_or_more, mfh_devel_pre) %>%
  group_by(condition) %>%
  summarise_each(funs(mean(., na.rm = TRUE),sd(., na.rm = TRUE),se=sd(., na.rm = TRUE)/sqrt(n())))  %>%
  dplyr::select(condition, contains("_se")) %>%
  mutate(across(2:11, round, 3)) %>%
  t()
 
## Create Table A7 SEs
 
stargazer(descripts_tab_cces_se)

```

### Figure A4. cces results

```{r Figure A4}

## Linear modeling

cces_mod <- lm(mfh_change ~ condition+ homeowner + p_id3 + latino + asian + black + 
                  white + age + 
                income_over100k + ba_or_more + gender +  zip_dens, data = cces)

linearHypothesis(cces_mod, "conditionStrong Support = conditionStrong Support Plus Distributive")

## Create Figure A4

figa4 <-
tidy(cces_mod)  %>%
  filter(grepl("condition", term)) %>%
  mutate(Condition = ifelse(grepl("Distributive", term), "Strong Support Plus Distributive", "Strong Support")) %>%
  ggplot() + 
  aes(x = Condition, y = estimate) + 
  geom_hline(yintercept = 0, lty = 3) + 
  geom_point() + 
  geom_linerange(aes(ymin = estimate - 1.645 * std.error, ymax = estimate + 1.645 * std.error), position = position_dodge(width = .35), lwd=1.5)+
  geom_linerange(aes(ymin = estimate - 1.96 * std.error, ymax = estimate + 1.96 * std.error), position = position_dodge(width = .35), lwd=.5)+
  labs(y = "", x = "") +
  theme_bw() +
  theme(text=element_text(size=12,  family="Times")) + 
  coord_flip()

ggsave("figs/fig_a4.pdf")

```

### Table A8. Mturk descriptives

```{r Table A8}

## Load MTurk Data

mturk_dat <- read_csv("replication_data/appendix/mturk_data_clean.csv")
mturk_dat$condition <- factor(mturk_dat$condition, levels = c("weak_support", "strong_support"), 
                       labels = c("Weak Support", "Strong Support"))

## Summarize MTurk means

descripts_mturk<- mturk_dat %>%
  group_by(condition) %>% 
  summarise("% Male"  = mean(gender, na.rm = TRUE),
            "% Latinx"  = mean(latino),
            "% Income > 100k"  = mean(income_over100),
            "% College Educated"  = mean(ba_or_more),
            "Average Age"  = mean(age),
            "Avg Support for Commercial Development"  = mean(commercial_devel),
            "Avg Support for Duplex Development"  = mean(duplex_devel),
            "Avg Support for Multifamily Housing Development, Pre-Treatment"  = mean(mfh_devel_pre),
            "Avg Support for Multifamily Housing Development, Post-Treatmen"  = mean(mfh_devel_post)) %>%
  mutate(across(2:10, round, 3)) %>%
  t() 

## Create Table A8 means

stargazer(descripts_mturk)

## Summarize Mturk SEs
 
descripts_mturk2 <- mturk_dat %>%
  dplyr::select(condition, gender, latino, age,  income_over100 ,  ba_or_more,  age,
               commercial_devel, duplex_devel,  mfh_devel_pre, mfh_devel_post) %>%
  group_by(condition) %>%
  summarise_each(funs(mean(., na.rm = TRUE),sd(., na.rm = TRUE),se=sd(., na.rm = TRUE)/sqrt(n())))  %>%
  dplyr::select(condition, contains("_se")) %>%
  mutate(across(2:9, round, 3)) %>%
  t()

## Create Table A8 SEs

stargazer(descripts_mturk2)
 
```

### Table A9. Mturk results

```{r Table A9}

## linear modeling

t1 <- lm(mfh_change ~ condition  + age + income + ba_or_more + gender + latino 
                  + zip_dens + dem_zip + commercial_devel + duplex_devel, data = mturk_dat)

t2 <- lm(supp_opp_self ~ condition  + age + income + ba_or_more + gender + latino 
                  + zip_dens + dem_zip + commercial_devel + duplex_devel, data = mturk_dat)

t3 <- lm(supp_opp_comm ~ condition  + age + income + ba_or_more + gender + latino 
                  + zip_dens + dem_zip + commercial_devel + duplex_devel, data = mturk_dat)

t4 <- lm(supp_opp_good ~ condition  + age + income + ba_or_more + gender + latino 
                  + zip_dens + dem_zip + commercial_devel + duplex_devel, data = mturk_dat)

t5 <- lm(supp_opp_hypo ~ condition  + age + income + ba_or_more + gender + latino 
                  + zip_dens + dem_zip + commercial_devel + duplex_devel, data = mturk_dat)

t6 <- lm(supp_opp_libl ~ condition  + age + income + ba_or_more + gender + latino 
                  + zip_dens + dem_zip + commercial_devel + duplex_devel, data = mturk_dat)

t7 <- lm(supp_opp_cons ~ condition  + age + income + ba_or_more + gender + latino 
                  + zip_dens + dem_zip + commercial_devel + duplex_devel, data = mturk_dat)

## Create Table A9

stargazer(t1, t2, t3, t4, t5, t6, t7,
          # this passes the lm_robust default SEs to stargazer
          se = starprep(t1, t2, t3, t4, t5, t6, t7, se_type ="HC2"),
          star.cutoffs = c(0.05, 0.01, 0.001), omit.stat=c("LL","ser","f", "adj.rsq"), 
          ci=TRUE, ci.level=0.95, single.row=FALSE,
           covariate.labels = c( "``Strong Support'' Condition",  
                                 "Age", "Income", "College Degree", 
                                 "Male", "Hispanic/Latino", "Zip Code Density", "Dem Zip",
                                 "Support for Commerical Devel",
                                 "Support for Duplex Devel"),
          omit = c("Constant"))

```

